unit Map_DBInfo;

interface

uses
  SysUtils, Classes, XMLDoc, XMLIntf, DataEngine, Class_DBInfo;

type
  TMap_DBInfo = class(TDataEngine)
  public
    function FuncXML_GetNodeName: string; override;
    function FuncXML_GetNodeKey(ABaseClass: TBaseClass): string; override;
    procedure FuncXML_AddChildren(NodeA: IXMLNode; ABaseClass: TBaseClass); override;
    function FuncXML_ReadNode(NodeA: IXMLNode): TBaseClass; override;
    
    function GetNextId(StrsList: TStringList): Integer;
  end;

implementation

uses
  UtilLib;



{ TMap_DBInfo }

procedure TMap_DBInfo.FuncXML_AddChildren(NodeA: IXMLNode;
  ABaseClass: TBaseClass);
begin
  with TDBInfo(ABaseClass) do
  begin
    NodeA.Attributes['FID'] := IntToStr(FID);
    NodeA.Attributes['FServer1'] := FServer1;
    NodeA.Attributes['FName1'] := FName1; 
    NodeA.Attributes['FServer2'] := FServer2;
    NodeA.Attributes['FName2'] := FName2;
  end;
end;

function TMap_DBInfo.FuncXML_GetNodeKey(ABaseClass: TBaseClass): string;
begin
  Result := IntToStr(TDBInfo(ABaseClass).FID);
end;

function TMap_DBInfo.FuncXML_GetNodeName: string;
begin
  Result := TDBInfo.ClassName;
end;

function TMap_DBInfo.FuncXML_ReadNode(NodeA: IXMLNode): TBaseClass;
begin
  Result := TDBInfo.Create;
  with TDBInfo(Result) do
  begin
    FID := StrToInt(NodeA.Attributes['FID']);
    FServer1 := NodeA.Attributes['FServer1'];
    FName1 := NodeA.Attributes['FName1']; 
    FServer2 := NodeA.Attributes['FServer2'];
    FName2 := NodeA.Attributes['FName2'];
  end;
end;

function TMap_DBInfo.GetNextId(StrsList: TStringList): Integer;
var
  ObjA: TDBInfo;
  I: Integer;
begin
  Result := 1;
  if StrsList = nil then Exit;
  if StrsList.Count = 0 then Exit;
  Result := TDBInfo(StrsList.Objects[0]).FID;
  for I := 1 to StrsList.Count - 1 do
  begin
    ObjA := TDBInfo(StrsList.Objects[I]);
    if Result < ObjA.FID then
    begin
      Result := ObjA.FID;
    end;
  end;
  Result := Result + 1;
end;

end.
